package com.itheima.day14_多线程.Test03;

public class Ticket implements Runnable{
    private int tickets = 100;
    private Object obj = new Object();
    @Override
    public void run() {
       while(true){
           synchronized (obj) {
               if(tickets >= 0){
                   try {
                       Thread.sleep(100);
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
                   System.out.println(Thread.currentThread().getName()+"正在售票,剩余票数还有"+tickets+"张");
                   tickets--;
               }else{
                   break;
               }
           }
       }
    }
}
